import java.util.Arrays;
import java.util.Scanner;

public class Solution {
    public int triangleNumber(int[] nums){
        Arrays.sort(nums);//对数组进行排序
        int ret = 0,len = nums.length;
        for (int i = len-1; i >= 2; i--) {//先固定最大的数
            //利用双指针快速统计出三元组的个数
            int left = 0,right = i-1;
            while(left < right){
                if(nums[left] + nums[right] > nums[i]){
                    ret += right-left;
                    right--;
                }else{
                    left++;
                }
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int n = in.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = in.nextInt();
            }
            Solution solution = new Solution();
            int result = solution.triangleNumber(nums);
            System.out.println(result);
        }
    }
}